package com.pinda.controller;


import com.pinda.service.IPdCoreStationService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageInfo;
import com.pinda.auth.entity.PdCoreStation;
import com.pinda.auth.view.StatusView;
import com.pinda.commonutils.Page;
import com.pinda.commonutils.Result;
import com.pinda.commonutils.StatusCode;
import com.pinda.service.IPdCoreStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 岗位 前端控制器
 * </p>
 *
 * @author 黄杰
 * @since 2023-06-13
 */
@RestController
@RequestMapping("/pd-core-station")
public class PdCoreStationController {
    @Resource
    private IPdCoreStationService iPdCoreStationService;


    @Autowired
    private IPdCoreStationService stationService;

    /**
     * 查询岗位
     * @param page
     * @return
     */
    @PostMapping("/querystation")
    public Result<PageInfo<StatusView>> querystationController(@RequestBody Page<StatusView> page){
        return new Result<>(true, StatusCode.OK,"查询成功",this.stationService.querystationService(page));
    }
    /**
     * 添加岗位
     */

    @PostMapping("/addstation")
    public Result addstation(@RequestBody PdCoreStation pdCoreStation){
        DateTime now = DateUtil.date();
        String format = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
        pdCoreStation.setCreateTime(format);
        this.stationService.save(pdCoreStation);
        return new Result(true,StatusCode.OK,"插入成功",1);
    }

    /**
     * 删除
     */
    @GetMapping("/deletestation/{id}")
    public Result deletestation(@PathVariable("id") String id){
        this.stationService.removeById(id);
       return new Result(true,StatusCode.OK,"删除成功",1);
    }
    /**
     * 修改
     */
    @PostMapping("/updatestation")
    public Result updatestation(@RequestBody PdCoreStation pdCoreStation){
        DateTime now = DateUtil.date();
        String format = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
        pdCoreStation.setUpdateTime(format);
        this.stationService.updateById(pdCoreStation);
        return new Result(true,StatusCode.OK,"修改成功",1);
    }


}
